import {call, put} from 'redux-saga/effects';
import {message} from 'antd';

function* callServiceApi(actionType, serviceApi, input, viewMessage = true) {
  try {
    const {data} = yield call(serviceApi, input);
    yield put(actionType.success()(data));
  } catch (error) {
    if (viewMessage) {
      message.error(error.toString());
    }
    yield put(actionType.failure()(error));
  }
}

export default callServiceApi;
